/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.File;
import java.io.FileInputStream;

/**
 * <p>Project: jse2302 - Ex1
 * <p>Powered by webrx On 2023-06-27 11:52:02
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex1 {
    public static void main(String[] args) {
        //c:/abc/a.jpg  c:/abc/b.png 判断两个是不是同一个文件
        String a = "c:/abc/a.jpg";
        String b = "c:/abc/c.jar";
        File ffa = new File(a);
        File ffb = new File(b);
        if (ffa.length() == ffb.length()) {
            try (var fa = new FileInputStream(a); var fb = new FileInputStream(b);) {
                long num = 0;
                while (fa.read() == fb.read()) {
                    ++num;
                    if (num == ffb.length()) {
                        break;
                    }
                }

                if (num == ffa.length()) {
                    System.out.println("是一个文件");

                } else {
                    System.out.println("不是一个文件");

                }

            } catch (Exception e) {

            }
        } else {
            System.out.println("不是一个文件");
        }
    }
}
